
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QPushButton, QWidget, QLCDNumber, QSlider, 
    QVBoxLayout, QApplication)
 
 
class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
    
    def onClick(self):
        self.btn.setText('信号发出')

    def initUI(self):
        
        lcd = QLCDNumber(self)
        sld = QSlider(Qt.Horizontal, self)
 
        vbox = QVBoxLayout()
        vbox.addWidget(lcd)
        vbox.addWidget(sld)
        
 
        self.setLayout(vbox)
        self.btn = QPushButton('确定')
        self.btn.clicked.connect(self.onClick)
        sld.valueChanged.connect(lcd.display)
        vbox.addWidget(self.btn)
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Signal & slot')
        self.show()
        
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())